package cmu;

import java.util.ArrayList;


public class Driver {
	
	
	public static void main(String args[]){
		boolean write = false;
		int sample = 5;
		
		if (args.length < 1){
			System.out.println("Usage: java Driver.class <write to files? n : y> [sampling rate=5(sec)]");
			System.out.println("Example: java Driver class y 5");
			System.exit(-1);
		}
		
		if (args[0].equals("y")){
			write =true;
		}
		
		if (args.length == 2){
			sample = Integer.parseInt(args[1]);
		}
		
		Monitor mtor = new Monitor();
		
		ArrayList<Integer> time = new ArrayList<Integer>();
		ArrayList<Double> cpu = new ArrayList<Double>();
		ArrayList<Double> mem = new ArrayList<Double>();
		ArrayList<Double> cpuW = new ArrayList<Double>();
		ArrayList<Double> swap = new ArrayList<Double>();
		ArrayList<Double> txNet = new ArrayList<Double>();
		ArrayList<Double> rxNet = new ArrayList<Double>();
		ArrayList<Double> rdDisk = new ArrayList<Double>();
		ArrayList<Double> wtDisk = new ArrayList<Double>();
		
		int count = 0;
		int cnt = 0;
		int size = 0;
		try{
			
			while(true){
				
				time.add(count);
				cpu.add(mtor.getCpuInfo());
				mem.add(mtor.getMemInfo());
				cpuW.add(mtor.getCpuWaitInfo());
				swap.add(mtor.getSwapInfo());
				txNet.add(mtor.getTxBytesInfo());
				rxNet.add(mtor.getRxBytesInfo());
				rdDisk.add(mtor.getRdDiskInfo());
				wtDisk.add(mtor.getWtDiskInfo());
/*				
				size = time.size();
				for (cnt =0; cnt < size; cnt++){
					System.out.print("\n");
					System.out.print("cpu=" + cpu.get(cnt) + "%, ");
					System.out.print("cpuWait=" + cpuW.get(cnt) + "%, ");
					System.out.print("mem=" + mem.get(cnt) + "%, ");
					System.out.print("swap=" + swap.get(cnt) + "%, ");
					System.out.print("txNet=" + txNet.get(cnt) + "KB, ");
					System.out.print("rxNet=" + rxNet.get(cnt) + "KB, ");
					System.out.print("rdDisk=" + rdDisk.get(cnt) + "KB, ");
					System.out.print("wtDisk=" + wtDisk.get(cnt) + "KB, ");
				}
*/	
				System.out.print("\ntime=" + count + "s, ");
				System.out.print("cpu=" + cpu.get(cnt) + "%, ");
				System.out.print("cpuWait=" + cpuW.get(cnt) + "%, ");
				System.out.print("mem=" + mem.get(cnt) + "%, ");
				System.out.print("swap=" + swap.get(cnt) + "%, ");
				System.out.print("txNet=" + txNet.get(cnt) + "KB, ");
				System.out.print("rxNet=" + rxNet.get(cnt) + "KB, ");
				System.out.print("rdDisk=" + rdDisk.get(cnt) + "KB, ");
				System.out.print("wtDisk=" + wtDisk.get(cnt) + "KB");
				
				cnt++;
				count = count + sample;
				Thread.sleep(sample*1000);
			}
			
		}catch (Exception e){
			System.out.println("Error in Driver: " + e.getMessage());
			e.getStackTrace();
		}
	}
}
